﻿//************************************************************************************************************
// CoNatural.Data.dll
// Author: Roger Torres
//************************************************************************************************************
// You can use, modify, and distribute the source code and executable programs based on the source code.
// This source code is provided "as is" and without warranties as to performance or merchantability. 
// The author and/or distributors of this source code may have made statements about this source code. 
// Any such statements do not constitute warranties and shall not be relied on by the user in deciding 
// whether to use this source code. This source code is provided without any express or implied warranties 
// whatsoever. Because of the diversity of conditions and hardware under which this source code may be used, 
// no warranty of fitness for a particular purpose is offered. The user is advised to test the source code 
// thoroughly before relying on it. The user must assume the entire risk of using the source code.
//************************************************************************************************************

using System;
using System.Data;
using System.Data.Odbc;
using System.Reflection;
using System.Collections.Generic;

namespace CoNatural.Data.Odbc {
	/// <summary>
	/// Basic Odbc provider 
	/// </summary>
	public class OdbcDbProvider : IDbProvider {
		/// <summary>
		/// Creates new odbc db provider.
		/// </summary>
		public OdbcDbProvider() { }

		#region IDbProvider Members

		public IDbConnection CreateConnection() {
			return new System.Data.Odbc.OdbcConnection();
		}

		public IDbCommand CreateCommand() {
			return new System.Data.Odbc.OdbcCommand();
		}

		public Parameter CreateParameter(string name, Type type, ParameterAttribute parameterAttribute) {
			return new Parameter(name, type, parameterAttribute);
		}

		public IDbDataParameter CreateDataParameter(string name, DbType dbType, ParameterDirection direction, int size, byte precision, byte scale, bool isNullable, string udtName, object value) {
			OdbcParameter p = new OdbcParameter();
			p.ParameterName = name;
			p.DbType = dbType;
			p.Direction = direction;
			if (size > 0)
				p.Size = size;
			else if (precision > 0) {
				p.Precision = precision;
				p.Scale = scale;
			}
			p.IsNullable = isNullable;
			Parameter.SetValue(p, value);
			return p;
		}

		public string ScriptName(ICommand command) {
			throw new NotImplementedException();
		}

		public string ScriptBatch(BatchExecutionContext batchCtx) {
			throw new NotImplementedException();
		}

		#endregion
	}
}
